package com.zztl.infiniteBand.presenter

import android.content.Context

import com.zztl.infiniteBand.base.BasePresenter
import com.zztl.infiniteBand.model.InviteBean
import com.zztl.infiniteBand.model.InviteDetailBean
import com.zztl.infiniteBand.model.PersonInfoBean
import com.zztl.infiniteBand.net.FilterSubscriber
import com.zztl.infiniteBand.net.FilterSubscriber2
import com.zztl.infiniteBand.net.RetorfitServiceManger
import com.zztl.infiniteBand.net.converter.DataConverter
import com.zztl.infiniteBand.net.requestBean.InviteParamsRequest
import com.zztl.infiniteBand.ui.view.mvpview.InviteView

/**
 * @desc
 * @auth ${user}
 * @time 2018/9/27  15:29
 */
class InvitePresenter : BasePresenter<InviteView>() {

    fun getInviteParams(request: InviteParamsRequest, context: Context) {
        addSubscribe(RetorfitServiceManger
                .observe(RetorfitServiceManger.instance!!.apiService.getInviteParams(DataConverter.instance.toJson(request)))
                .subscribe(object : FilterSubscriber<InviteBean>(context) {


                    override fun success(bean: InviteBean) {
                        view!!.getParamsSuccess(bean)
                    }

                    override fun fail() {

                    }
                }))
    }


    fun getInviteDetail(request: InviteParamsRequest, context: Context) {
        addSubscribe(RetorfitServiceManger
                .observe(RetorfitServiceManger.instance!!.apiService.getInviteDetail(DataConverter.instance.toJson(request)))
                .subscribe(object : FilterSubscriber2<InviteDetailBean>(context) {


                    override fun success(bean: InviteDetailBean) {
                        view!!.getInviteDetail(bean)
                    }

                    override fun fail(msg: String?) {

                    }
                }))
    }

    fun getUserInfo(context: Context) {
        addSubscribe(RetorfitServiceManger
                .observe(RetorfitServiceManger.instance!!.apiService
                .getInfo("")).subscribe(object : FilterSubscriber<PersonInfoBean>(context) {
            override fun success(infoBean: PersonInfoBean) {
                view!!.getInfoSuccess(infoBean)
            }


        }))
    }


}
